package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Train;
import com.hengxinguotong.zhihuichengjian.utils.SpannableStringUtils;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.MarqueeTextView;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/11/1
 */

public class StudyDetailAdapter extends RecyclerAdapter<Train, StudyDetailAdapter.StudyDetailViewHolder> {

    public StudyDetailAdapter(Context context, List<Train> dataList) {
        super(context, dataList);
    }

    @Override
    public StudyDetailViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_study_detail, null);
        return new StudyDetailViewHolder(view);
    }

    @Override
    public void onBindViewHolder(StudyDetailViewHolder holder, int position) {
        holder.bindData(dataList.get(position));
    }

    public class StudyDetailViewHolder extends RecyclerAdapter.BaseViewHolder<Train>{
        @BindView(R.id.result_img)
        ImageView resultImg;
        @BindView(R.id.name_tv)
        MarqueeTextView nameTv;
        @BindView(R.id.hour_tv)
        HXTextView hourTv;
        @BindView(R.id.record_tv)
        HXTextView recordTv;
        @BindView(R.id.fen_tv)
        HXTextView fenTv;
        @BindView(R.id.study_type_tv)
        HXTextView studyTypeTv;
        @BindView(R.id.study_unit_tv)
        HXTextView studyUnitTv;
        @BindView(R.id.date_tv)
        HXTextView dateTv;
        @BindView(R.id.time_tv)
        HXTextView timeTv;

        public StudyDetailViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void bindData(final Train train){
            if(train.getiSPass().equals("1"))//0:不合格 1:合格
            {
                resultImg.setImageResource(R.mipmap.pass);
            }else{
                resultImg.setImageResource(R.mipmap.no_pass);
            }
            nameTv.setText(train.getTrainName());
            if(train.getsGrade() != -1){
//                recordTv.setText(SpannableStringUtils.getBuilder(String.valueOf(train.getsGrade()))
//                        .setBoldItalic().setFontTextSize(Utils.sp2px(context, 25)).setForegroundColor(Color.parseColor("#f9881c"))
//                        .append("分").setFontTextSize(Utils.sp2px(context, 12)).setForegroundColor(Color.parseColor("#999999"))
//                        .create());
                recordTv.setText(train.getsGrade() + " ");
                recordTv.setTextColor(context.getResources().getColor(R.color.color_ff9881c));
                recordTv.setTextSize(25);
                fenTv.setVisibility(View.VISIBLE);
            }else {
                recordTv.setText(R.string.no_exam);
                recordTv.setTextColor(context.getResources().getColor(R.color.color_999999));
                recordTv.setTextSize(18);
                fenTv.setVisibility(View.GONE);
            }
            hourTv.setText(train.getTrainPeriod() + "学时");
            studyUnitTv.setText(train.getTrainDepart());
            studyTypeTv.setText(train.getTrainType());
            dateTv.setText(train.getTrainTime());

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClickListener.onItemClick(train);
                }
            });
        }
    }

}
